package main

import (
	"encoding/json"
	"fmt"
	"reflect"
	"serialize"
)

func example1() {
	// Test to test embeded
	type Test struct {
		TestName string
	}

	// Man man struct
	type Man struct {
		Name  string
		Age   int `max:"90"`
		Flo   float32
		Hobby []string
		Mapp  map[string]int
		Sex   bool
		Test  Test
	}

	type F struct {
		Name string
	}

	type L struct {
		Name string // exported
		name string // not exported
	}

	var T = struct {
		A string `json:"x"`
		B int    `json:"y"`
		C bool   `json:"z"`
		D struct {
			E string `json:"jkl"`
		} `json:"nested"`
		F F `json:"def"`
		G []string
		H []int
		I [5]string
		J []F
		K map[string]int
		L
	}{
		A: "a-value",
		B: 2,
		C: true,
	}
	T.D.E = "e-value"
	T.F = F{"kaijie"}
	T.G = []string{"slice1", "slice2"}
	T.H = []int{1, 2, 3}
	T.I = [5]string{"q", "w", "e", "r", "t"}
	T.J = []F{{"J.1"}}
	T.K = map[string]int{"unix": 1}
	T.L = L{"Exported", "unx"}

	bytes, err := serialize.JSONMarshal(T)
	if err != nil {
		fmt.Println(err)
	}
	str := string(bytes)
	expeted, _ := json.Marshal(T)
	fmt.Printf("got %s\nexp %s\ncorrect:%v\n", str, expeted, reflect.DeepEqual(string(expeted), str))
}

func example2() {
	type Road struct {
		Name   string
		Number int `myTag:"Num"`
	}
	road := Road{"Diamond Fork", 29}

	// New a Struct
	s := serialize.New(road)
	// Change TagName
	s.TagName = "myTag"
	// To show clearly, we ignore err because they won't get error
	got, _ := s.Marshal()

	b, _ := json.Marshal(
		struct {
			Name string
			Num  int
		}{
			"Diamond Fork",
			29,
		})
	exp := string(b)
	fmt.Printf("got %s\nexp %s\ncorrect:%v\n", got, exp, reflect.DeepEqual(exp, got))
}

func main() {
	example1()
	example2()
}
